/**
 *高校基本信息管理模块
 **/
$(function () {
    //学部列表
    $('#manager-school-college').datagrid({
        url: Think.APP + "School/index&cmd=InfoCollege", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#school-college-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
                {title: 'ID', field: '', checkbox: true},
                {field: 'ico_id', title: '学部编号', width: 100, align: 'center'},
                {field: 'ico_name', title: '学部名称', width: 100, align: 'center'},
                {field: 'ico_tel', title: '联系方式', width: 100, align: 'center'},
                {field: 'ico_teacher', title: '负责人', width: 100, align: 'center'},
            ]],
        onClickRow: function (rowIndex, rowData) {//单击事件
            $('#manager-school-college').datagrid("clearChecked"); //取消所有行的选中
            $('#manager-school-college').datagrid("selectRow", rowIndex);  //选中当前行
        },
        onDblClickRow: function (field, row) {
            var url = Think.APP + "School/edit&cmd=InfoCollege&ico_id=" + row.ico_id;
            Xwindow.baseDialogInit("#manager-school-college", "#add-college-form", "修改学部",url,row,3);
        }
    });

    //专业列表
    $('#manager-school-discipline').datagrid({
        url: Think.APP + "School/index&cmd=InfoDiscipline", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#school-discipline-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
                {title: 'ID', field: '', checkbox: true},
                {field: 'id_id', title: '专业编号', width: 100, align: 'center'},
                {field: 'id_name', title: '专业名称', width: 100, align: 'center'},
                {field: 'id_teacher', title: '负责人', width: 100, align: 'center'},
                {field: 'id_time', title: '开设时间', width: 100, align: 'center'},
                {field: 'ico_id', title: '学部', width: 100, align: 'center', formatter: function (value, row, index) {
                        if (value <= 0) {
                            return "无";
                        }
                        return Store().converter(app_data.info.college("STORE"), value);
                    }},
            ]],
        onClickRow: function (rowIndex, rowData) {//单击事件
            $('#manager-school-discipline').datagrid("clearChecked"); //取消所有行的选中
            $('#manager-school-discipline').datagrid("selectRow", rowIndex);  //选中当前行
        },
        onDblClickRow: function (field, row) {
            var url = Think.APP + "School/edit&cmd=InfoDiscipline&id_id=" + row.id_id;
            Xwindow.baseDialogInit("#manager-school-discipline", "#add-discipline-form", "修改专业",url,row,3);
        }
    });

    //班级列表
    $('#manager-school-classinfo').datagrid({
        url: Think.APP + "School/index&cmd=InfoClass", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#school-classinfo-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
                {title: 'ID', field: '', checkbox: true},
                {field: 'icl_id', title: '班级编号', width: 100, align: 'center'},
                {field: 'ico_id', title: '学部', width: 100, align: 'center', formatter: function (value, row, index) {
                        if (value <= 0) {
                            return "无";
                        }
                        return Store().converter(app_data.info.college("STORE"), value);
                    }},
                {field: 'id_id', title: '专业', width: 100, align: 'center', formatter: function (value, row, index) {
                        if (value <= 0) {
                            return "无";
                        }
                        return Store().converter(app_data.info.discipline("STORE"), value);
                    }},
                {field: 'icl_number', title: '班级', width: 100, align: 'center'},
                {field: 'icl_teacher', title: '负责人', width: 100, align: 'center'},
                {field: 'icl_year', title: '开设年份【年级】', width: 100, align: 'center'},
                {field: 'icl_note', title: '备注', width: 100, align: 'center'}
            ]],
        onClickRow: function (rowIndex, rowData) {//单击事件
            $('#manager-school-classinfo').datagrid("clearChecked"); //取消所有行的选中
            $('#manager-school-classinfo').datagrid("selectRow", rowIndex);  //选中当前行
        },
        onDblClickRow:function(field, row){
            var url =  Think.APP + "School/edit&cmd=InfoClass&icl_id=" + row.icl_id;
            //打开弹出窗口
            Xwindow.baseDialogInit("#manager-school-classinfo", "#add-class-form", "修改班级",url,row,3);
        }
    });
    
    //添加方法
    school_toolbar = {
        addCollege: function () {  //添加学部信息
            var url =  Think.APP + "School/insert&cmd=InfoCollege";
            //打开弹出窗口
            Xwindow.baseDialogInit("#manager-school-college", "#add-college-form", "添加学部",url);
        },
        addDiscipline:function(){ //添加专业信息
            var url =  Think.APP + "School/insert&cmd=InfoDiscipline";
            //打开弹出窗口
            Xwindow.baseDialogInit("#manager-school-discipline", "#add-discipline-form", "添加专业",url);
        },
        addClass:function(){ //添加班级信息
            var url =  Think.APP + "School/insert&cmd=InfoClass";
            //打开弹出窗口
            Xwindow.baseDialogInit("#manager-school-classinfo", "#add-class-form", "添加班级",url);
        },
        xunkeByClass:function(){
            var url = Think.APP + "Curriculum/xuankeByClass";
            //获取选中的数据信息
            var selectData = $("#manager-school-classinfo").datagrid("getSelections");
            var data = [];
            if (selectData.length > 0) {
                //组装数据
                for (var i = 0; i < selectData.length; i++) {
                    data.push(selectData[i].icl_id);
                }
            }
            var loaddata = {"icl_id": data.join(',')};
            Xwindow.baseDialogInit("#manager-school-classinfo", "#add-xuankeclass-form", "按班级选课", url, loaddata, 2, true);
        },
        xunkeByMajor:function(){
            var url = Think.APP + "Curriculum/xuankeByMajor";
            //获取选中的数据信息
            var selectData = $("#manager-school-discipline").datagrid("getSelections");
            var data = [];
            if (selectData.length > 0) {
                //组装数据
                for (var i = 0; i < selectData.length; i++) {
                    data.push(selectData[i].id_id);
                }
            }
            var loaddata = {"id_id": data.join(',')};
            Xwindow.baseDialogInit("#manager-school-discipline", "#add-xuankemajor-form", "按专业选课", url, loaddata, 2, true);
        },
        //打开专业搜索弹窗
        openSearchMajor:function(){
            //打开弹出窗口
            Xwindow.baseDialogInit("#manager-school-discipline", "#search-discipline-form", "高级搜索",'search');
        },
        //打开班级搜索弹窗
        openSearchClassInfo:function(){
            //打开弹出窗口
            Xwindow.baseDialogInit("#manager-school-classinfo", "#search-classinfo-form", "高级搜索",'search');
        },
        //删除学部信息
        deleteInfoCollege:function(){
            var url =  Think.APP + "School/del&cmd=InfoCollege";
            Xwindow.baseDelete( "#manager-school-college",url,"ico_id");
        },
        //删除专业信息
        deleteDiscipline:function(){
            var url =  Think.APP + "School/del&cmd=InfoDiscipline";
            Xwindow.baseDelete( "#manager-school-discipline",url,"id_id");
        },
        //删除班级信息
        deleteClassinfo:function(){
            var url =  Think.APP + "School/del&cmd=InfoClass";
            Xwindow.baseDelete( "#manager-school-classinfo",url,"icl_id");
        }
        
    };

});